package com.itheima.article.controller;


import com.itheima.article.dto.ArticleHomeDto;
import com.itheima.article.pojo.ApArticle;
import com.itheima.article.service.ApArticleService;
import com.itheima.article.vo.ArticleInfoVo;
import com.itheima.common.constants.BusinessConstants;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.core.controller.AbstractCoreController;

import java.util.Map;

/**
 * @description <p>已发布的文章信息</p>
 *
 * @version 1.0
 * @package com.itheima.article.controller
 */
@Api(value="ApArticleController",tags = "已发布的文章信息")
@RestController
@RequestMapping("/article")
public class ApArticleController extends AbstractCoreController<ApArticle> {

    private ApArticleService apArticleService;

    @Autowired
    public ApArticleController(ApArticleService apArticleService) {
        super(apArticleService);
        this.apArticleService=apArticleService;
    }
    /**
     * APP端加载第一页数据
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public PageResultVo<ApArticle> load(@RequestBody ArticleHomeDto dto){
        PageResultVo<ApArticle> resultVo = apArticleService.findPage(dto, BusinessConstants.ArticleConstants.LOAD_NEW);
        return resultVo;
    }

    /**
     * APP端加载第一页数据
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public PageResultVo<ApArticle> loadMore(@RequestBody ArticleHomeDto dto){
        PageResultVo<ApArticle> resultVo = apArticleService.findPage(dto, BusinessConstants.ArticleConstants.LOAD_MORE);
        return resultVo;
    }

    /**
     * APP端加载第一页数据
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public PageResultVo<ApArticle> loadNew(@RequestBody ArticleHomeDto dto){
        PageResultVo<ApArticle> resultVo = apArticleService.findPage(dto, BusinessConstants.ArticleConstants.LOAD_NEW);
        return resultVo;
    }

    /**
     * 加载文章详情
     * @param paramMap
     * @return
     */
    @PostMapping("/load_article_info")
    public ResultVo<ArticleInfoVo> loadArticleInfo(@RequestBody Map<String,String> paramMap){
        ArticleInfoVo vo = apArticleService.loadArticleInfo(paramMap);
        return ResultVo.ok(vo);
    }
}
